package com.example.practice.service.impl;

import com.example.practice.entity.FeedUrl;
import com.example.practice.entity.Feekback;
import com.example.practice.dao.FeekbackDao;
import com.example.practice.entity.pageMsg;
import com.example.practice.entity.respMsg;
import com.example.practice.service.FeekbackService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Feekback)表服务实现类
 *
 * @author makejava
 * @since 2023-12-21 15:53:22
 */
@Service("feekbackService")
public class FeekbackServiceImpl implements FeekbackService {
    @Resource
    private FeekbackDao feekbackDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Feekback queryById(Integer id) {
        return this.feekbackDao.queryById(id);
    }


    /**
     * 分页查询
     *
     * @param feekback 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */


    /**
     * 新增数据
     *
     * @param feekback 实例对象
     * @return 实例对象
     */
    @Override
    public Feekback insert(Feekback feekback) {
        this.feekbackDao.insert(feekback);
        return feekback;
    }

    /**
     * 修改数据
     *
     * @param feekback 实例对象
     * @return 实例对象
     */
    @Override
    public Feekback update(Feekback feekback) {
        this.feekbackDao.update(feekback);
        return this.queryById(feekback.getId());
    }

    /**
     * 修改状态status
     */
    @Override
    public int updateStatus(Integer id) {
        return this.feekbackDao.updateStatus(id);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.feekbackDao.deleteById(id) > 0;
    }

    @Override
    public respMsg queryAllByLimit(Integer uid, pageMsg pageMsg) {
        PageHelper.startPage(pageMsg.getPage(), pageMsg.getSize());
        List<Feekback> feekbacks = this.feekbackDao.queryAllByLimit(uid);
        PageInfo<Feekback> feekbackPageInfo = new PageInfo<>(feekbacks);
        return new respMsg(1, null, feekbacks, feekbackPageInfo.getTotal());
    }

    @Override
    public int addFeekback(Feekback feekback) {
        if (this.feekbackDao.addFeekback(feekback) == 1) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public List<Feekback> getByUid(Integer uid) {
        return this.feekbackDao.getByUid(uid);
    }

    @Override
    public respMsg queryAll(pageMsg pageMsg) {
        PageHelper.startPage(pageMsg.getPage(), pageMsg.getSize());
        List<Feekback> feekbacks = this.feekbackDao.queryAll();
        PageInfo<Feekback> feekbackPageInfo = new PageInfo<>(feekbacks);
        return new respMsg(1, null, feekbacks, feekbackPageInfo.getTotal());
    }

    @Override
    public respMsg searchStatus1(Integer status, pageMsg pageMsg) {
        PageHelper.startPage(pageMsg.getPage(), pageMsg.getSize());
        List<Feekback> feekbacks = this.feekbackDao.searchStatus(status);
        PageInfo<Feekback> feekbackPageInfo = new PageInfo<>(feekbacks);
        return new respMsg(1, null, feekbacks, feekbackPageInfo.getTotal());
    }

    @Override
    public List<Feekback> getAllFeek() {
        List<Feekback> feekbackList = this.feekbackDao.queryAll();
        return feekbackList;
    }

    @Override
    public List<Feekback> getFeekback(String aname, String uname, Integer status) {
        return this.feekbackDao.getFeekback(aname, uname, status);
    }

    @Override
    public Integer saveFeedUrl(List<FeedUrl> fileUrl) {
        return this.feekbackDao.saveFeedUrl(fileUrl);
    }

    @Override
    public List<FeedUrl> selectFeedFile(Integer fid, Integer uid) {
        return this.feekbackDao.selectFeedFile(fid, uid);
    }

    @Override
    public List<Feekback> findAllFeedByUid(Integer uid) {
        return this.feekbackDao.findAllFeedByUid(uid);
    }
}
